package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.ScanOrdersModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.ScanOrdersView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ZHY_9 on 2017/6/14.
 */

public class ScanOrdersPresenter extends BasePresenter {

    private ScanOrdersView scanOrdersView;

    private int pageCount;

    public ScanOrdersPresenter(ScanOrdersView scanOrdersView) {
        this.scanOrdersView = scanOrdersView;
        pageCount = 1;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public void loadScanOrdersList(final Context context) {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> params = new HashMap<>();
        params.put("key", ConfigValue.DATA_KEY);
        params.put("page", String.valueOf(pageCount));
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "scan/scanOrderList", params,
                new BaseDelegate.ResultCallback<ScanOrdersModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(ScanOrdersModel response, Object tag) {
                dismiss();
                scanOrdersView.getScanOrdersList(response);
            }
        }, true);

    }
}
